<template>
  <div>
    <bread></bread>
    <el-card>
      <!-- 2 为ECharts准备一个具备大小（宽高）的Dom -->
      <div id="main" style="width: 750px;height:400px;"></div>
    </el-card>
  </div>
</template>
<script>
import bread from "../bread";
// 1  导入
// import echarts from "echarts"
import API from "../API/Api"
import * as echarts from "echarts";
import _ from "lodash";
export default {
  name: "",
  data() {
    return {
      option: {
        title: {
          text: "用户来源"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3"
            }
          }
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ]
      }
    };
  },
  created() {},
  mounted() {
    var myChart = echarts.init(document.getElementById("main"));
    API.reports().then(res => {
      console.log(res);
      if (res.meta.status !== 200) {
        return this.$message.error("获取折线图数据失败!");
      }
      const result = _.merge(res.data, this.option);
      myChart.setOption(result);
    });
  },
  methods: {},
  computed: {},
  components: {
    bread
  },
  watch: {},
  getters: {}
};
</script>

<style scoped>
</style>